<template>
  <div>
    <h1>home</h1>
    <el-button type="primary" @click="goLogin">{{ login_info }}</el-button>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      login_info: "登录",
    };
  },
  //逻辑：一般 都是有用户名直接显示用户名  没有用户名就是登录
  // 更改用户名实际上更改的就是login_info
  created() {
    //
    if (this.user_name) {
      this.login_info = this.user_name;
    }
  },
  computed: {
    ...mapState("user_m", ["user_name"]),
  },
  methods: {
    goLogin() {
      //逻辑：有用户名 显示用户名，点击不进行跳转 没有用户名 显示登录并点击能进行跳转
      if (this.user_name) {
        this.login_info = this.user_name;
      } else {
        this.$router.push({
          name: "login",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>